﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Class_Entity;
using BussinessObject;
using System.Data;
using System.Data.SqlClient;

public partial class WebApplication_EditAccountDetails : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["username"] == null)
        {
            Response.Redirect("Login.aspx");
        }
        else
            if (!Page.IsPostBack)
            {
                loadData();
            }
    }
    private void loadData()
    {
        Label1.Text = Session["Username"].ToString();

        Users us = new Users();
        BOUsers bus = new BOUsers();

        us.Username = Session["Username"].ToString();

        DataSet ds = new DataSet();
        ds = bus.Load_UserDetail(us);
        txtFName.Text = ds.Tables[0].Rows[0][3].ToString();
        txtEmail.Text = ds.Tables[0].Rows[0][4].ToString();
        txtPhone.Text = ds.Tables[0].Rows[0][6].ToString();
        txtAddress.Text = ds.Tables[0].Rows[0][5].ToString();
    }
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        Users us = new Users();
        BOUsers bus = new BOUsers();

        us.Username = Session["Username"].ToString();

        DataSet ds = new DataSet();
        ds = bus.Load_UserDetail(us);
        string pass = ds.Tables[0].Rows[0][2].ToString();
        if (pass != txtPass.Text)
        {
            Label2.Text = "Password is not correct!";
        }
        else
        {
            us.Password = txtNPass.Text.Trim();
            us.Fullname = txtFName.Text.Trim();
            us.Email = txtEmail.Text.Trim();
            us.Tel = txtPhone.Text.Trim();
            us.Address = txtAddress.Text.Trim();
            bus.Edit_Users(us);
            Session["RoleCode"] = null;
            Session["Username"] = null;
            Response.Redirect("Login.aspx");
        }


    }
}